var contextPath = '/ab';
var basicUrl = window.location.origin + contextPath;

function logout(){
    this.location.href = basicUrl + '/logout';
};

//Vue.config.debug = true;

Vue.component('group-list', {	
    props : ['list'],
    template : '#groupListTemplate',
    methods: {
    	buttonClick: function(event, actionType){
    		
    	      console.log("Enter buttonClick()");
    	      console.log("event.target: ", event.target);
              console.log("actionType: ", actionType);

    	      console.log("emit to button-click, which is bound to realActionHandler()");
    	      
    	      this.$emit('button-click', event.target, actionType);
    	}    	
    }
});

Vue.component('friend-list', {   
    props : ['list'],
    template : '#friendListTemplate',
    methods: {
    	buttonClick: function(event, actionType){
    		
    	      console.log("Enter buttonClick()");
    	      console.log("event.target: ", event.target);
              console.log("actionType: ", actionType);

    	      console.log("emit to button-click, which is bound to realActionHandler()");
    	      
    	      this.$emit('button-click', event.target, actionType);
    	}    	
    }    
});

Vue.component('member-list', {   
    props : ['list', 'group-name'],
    template : '#memberListTemplate',
    methods: {
        buttonClick: function(event, actionType){
            
              console.log("Enter buttonClick()");
              console.log("event.target: ", event.target);
              console.log("actionType: ", actionType);

              console.log("emit to button-click, which is bound to realActionHandler()");
              
              this.$emit('button-click', event.target, actionType);
        }       
    }
});

Vue.component('send-msg', {   
    props : ['list'],
    template : '#sendMsgTemplate',
    data: function(){
    	return {
    		requestParam: {
    			textToSend: '',
    			//imgToSend: 'C:/Users/Administrator/workspace/astroboy4web/src/main/webapp/upload/IMG_20151112_104447.jpg',
    			imgToSend: '',
    			wxGroupSelected: [],
                selectedImgUrl: ''
    		}
    	}
    },
    methods: {
        removePic: function(){
            this.requestParam.imgToSend = '';
            this.requestParam.selectedImgUrl = '';
            //清除file input
            $("#imgToSend").val("");

        },
        buttonClick: function(event, actionType){
            
              console.log("Enter buttonClick()");
              console.log("event.target: ", event.target);
              console.log("actionType: ", actionType);

              console.log("emit to button-click, which is bound to realActionHandler()");
              
              this.$emit('button-click', event.target, actionType);
        },
        
        sendMsgFormSubmit: function(){
            
            console.log("Enter sendMsgFormSubmit()");

            console.log('textToSend', this.requestParam.textToSend);
            console.log('imgToSend', this.requestParam.imgToSend);
            console.log('wxGroupSelected', this.requestParam.wxGroupSelected);

            var self = this;

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/sendMsg',
                data : {
                    'textToSend': this.requestParam.textToSend,
                    'imgToSend': this.requestParam.imgToSend,
                    'wxGroupSelected': this.requestParam.wxGroupSelected.toString()
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(resp.status){
                        //消息发送成功，清除文字输入框以便输入下一条消息
                        self.requestParam.textToSend = '';
                        self.requestParam.imgToSend = '';
                        self.requestParam.selectedImgUrl = '';

                        //清除file input
                        $("#imgToSend").val("");

                    }else{
                        alert(resp.description);
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

            //看来没有必要把参数发给父组件来调用POST请求，直接在本组件中就可以完成了，所以注释掉下面两行
            //console.log("emit to form-submit-click, which is bound to realFormSubmitHandler()");            
            //this.$emit('form-submit-click', actionType, this.requestParam);
      },
      
      sendMsgFormReset: function(){
          console.log("Enter sendMsgFormReset()");
          this.requestParam.textToSend = '';
          this.requestParam.imgToSend = '';
          this.requestParam.wxGroupSelected = [];
          this.requestParam.selectedImgUrl = '';

          //清除file input
          $("#imgToSend").val("");

      },
      
      fileChange: function(event){
          console.log("Enter fileChange()");
          console.log("event.target.files[0]: ", event.target.files[0]);        
          console.log("event.target.files[0].name: ", event.target.files[0].name);

          formdata = new FormData();
          formdata.append('fileContent', event.target.files[0]);
          formdata.append('expectedFolder','temp');
          formdata.append('expectedFileName','');
          
          axios({
              url: basicUrl + '/robot/upload',
              method: 'post',
              data: formdata,
              headers: {'Content-Type': 'application/multipart/form-data'}
          })
          .then(function(resp) {

              console.log("resp.data:", resp.data);
              this.requestParam.imgToSend = resp.data.imgToSend;
              this.requestParam.selectedImgUrl = resp.data.selectedImgUrl;

         }.bind(this))
         .catch(function(error) {
              alert("axios异常，请查看系统日志以排查问题");
         });
      }
    }
});

Vue.component('auto-reply-list', {	
    props : ['list'],
    template : '#autoReplyListTemplate',
    methods: {
    	buttonClick: function(event, actionType){
    		
    	      console.log("Enter buttonClick()");
    	      console.log("event.target: ", event.target);
              console.log("actionType: ", actionType);

              if(actionType == 'REMOVE_AUTO_REPLY'){
                  var r = confirm("确定要删除吗？");
                  if (!r)
                  {
                      return;
                  }
              };

    	      console.log("emit to auto-reply-button-click, which is bound to realAutoReplyActionHandler()");
    	      this.$emit('auto-reply-button-click', event.target, actionType);
    	}    	
    }
});

Vue.component('create-auto-reply', {
    props : ['list'],
    template : '#createAutoReplyTemplate',
    data: function(){
    	return {
    		requestParam: {
    			keyword: '',
    			ignoredSender: '',
    			textToSend1: '',
    			textToSend2: '',
    			imgToSend: '',
    			wxGroupSelected: [],
                selectedImgUrl: ''
            },
            mode: 'CREATE_MODE'
    	}
    },
    methods: {
        removePic: function(){
            this.requestParam.imgToSend = '';
            this.requestParam.selectedImgUrl = '';
            //清除file input
            $("#imgToSend").val("");

        },
        formSubmit: function(){

            console.log("Enter formSubmit()");

            console.log('keyword', this.requestParam.keyword);
            console.log('ignoredSender', this.requestParam.ignoredSender);
            console.log('textToSend1', this.requestParam.textToSend1);
            console.log('textToSend2', this.requestParam.textToSend2);
            console.log('imgToSend', this.requestParam.imgToSend);
            console.log('wxGroupSelected', this.requestParam.wxGroupSelected);
            console.log('mode', this.mode);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/autoReply',
                data : {
                    'keyword': this.requestParam.keyword,
                    'ignoredSender': this.requestParam.ignoredSender,
                    'textToSend1': this.requestParam.textToSend1,
                    'textToSend2': this.requestParam.textToSend2,
                    'imgToSend': this.requestParam.imgToSend,
                    'wxGroupSelected': this.requestParam.wxGroupSelected.toString(),
                    'mode': this.mode
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "auto-reply-list";
                        customContent.resultList = resp;
                        breadcrumb.currentLocation = "群自动回复关键词列表";
                    }else if(!resp.status){
                        alert(resp.description);
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

            //看来没有必要把参数发给父组件来调用POST请求，直接在本组件中就可以完成了，所以注释掉下面两行
            //console.log("emit to form-submit-click, which is bound to realFormSubmitHandler()");            
            //this.$emit('form-submit-click', actionType, this.requestParam);
      },

        formReset: function(){
          console.log("Enter formReset()");

          this.requestParam.keyword = '';
          this.requestParam.ignoredSender = '';
          this.requestParam.textToSend1 = '';
          this.requestParam.textToSend2 = '';
          this.requestParam.imgToSend = '';
          this.requestParam.wxGroupSelected = [];
          this.requestParam.selectedImgUrl = '';

            //清除file input
            $("#imgToSend").val("");
      },
      
      fileChange: function(event){
          console.log("Enter fileChange()");
          console.log("event.target.files[0]: ", event.target.files[0]);        
          console.log("event.target.files[0].name: ", event.target.files[0].name);

          formdata = new FormData();
          formdata.append('fileContent', event.target.files[0]);
          formdata.append('expectedFolder','autoReply');
          formdata.append('expectedFileName','');
          
          axios({
              url: basicUrl + '/robot/upload',
              method: 'post',
              data: formdata,
              headers: {'Content-Type': 'application/multipart/form-data'}
          })
          .then(function(resp) {

              console.log("resp.data:", resp.data);

              if(resp.data.status == 'true'){
                  this.requestParam.imgToSend = resp.data.imgToSend;
                  this.requestParam.selectedImgUrl = resp.data.selectedImgUrl;
              }else{
                  alert("resp.data.description");
              }

         }.bind(this))
         .catch(function(error) {
              alert("axios异常，请查看系统日志以排查问题");
         });
      }
    }
});

Vue.component('create-welcome-msg', {
    props : ['list'],
    template : '#createWelcomeMsgTemplate',
    data: function(){
        return {
            requestParam: {
                keyword: '',
                threshold: '',
                textToSend1: '',
                textToSend2: '',
                imgToSend: '',
                wxGroupSelected: [],
                selectedImgUrl: ''
            },
            mode: 'CREATE_MODE'
        }
    },
    methods: {
        removePic: function(){
            this.requestParam.imgToSend = '';
            this.requestParam.selectedImgUrl = '';
            //清除file input
            $("#imgToSend").val("");
        },
        formSubmit: function(){

            console.log("Enter formSubmit()");

            console.log('keyword', this.requestParam.keyword);
            console.log('threshold', this.requestParam.threshold);
            console.log('textToSend1', this.requestParam.textToSend1);
            console.log('textToSend2', this.requestParam.textToSend2);
            console.log('imgToSend', this.requestParam.imgToSend);
            console.log('wxGroupSelected', this.requestParam.wxGroupSelected);
            console.log('mode', this.mode);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/welcomeMsg',
                data : {
                    'keyword': this.requestParam.keyword,
                    'threshold': this.requestParam.threshold,
                    'textToSend1': this.requestParam.textToSend1,
                    'textToSend2': this.requestParam.textToSend2,
                    'imgToSend': this.requestParam.imgToSend,
                    'wxGroupSelected': this.requestParam.wxGroupSelected.toString(),
                    'mode': this.mode
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "welcome-msg-list";
                        customContent.resultList = resp;
                        breadcrumb.currentLocation = "欢迎消息列表";
                    }else if(!resp.status){
                        alert(resp.description);
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        },

        formReset: function(){
            console.log("Enter formReset()");

            this.requestParam.keyword = '';
            this.requestParam.threshold = '';
            this.requestParam.textToSend1 = '';
            this.requestParam.textToSend2 = '';
            this.requestParam.imgToSend = '';
            this.requestParam.wxGroupSelected = [];
            this.requestParam.selectedImgUrl = '';

            //清除file input
            $("#imgToSend").val("");
        },

        fileChange: function(event){
            console.log("Enter fileChange()");
            console.log("event.target.files[0]: ", event.target.files[0]);
            console.log("event.target.files[0].name: ", event.target.files[0].name);

            formdata = new FormData();
            formdata.append('fileContent', event.target.files[0]);
            formdata.append('expectedFolder','welcomeMsg');
            formdata.append('expectedFileName','');

            axios({
                url: basicUrl + '/robot/upload',
                method: 'post',
                data: formdata,
                headers: {'Content-Type': 'application/multipart/form-data'}
            })
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    if(resp.data.status == 'true'){
                        this.requestParam.imgToSend = resp.data.imgToSend;
                        this.requestParam.selectedImgUrl = resp.data.selectedImgUrl;
                        $("#imgToSend").val("");
                    }else{
                        alert("resp.data.description");
                    }

                }.bind(this))
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        }
    }
});

Vue.component('create-admin', {
    props : ['list'],
    template : '#createAdminTemplate',
    data: function(){
        return {
            requestParam: {
                account: '',
                password: '',
                passwordAgain: ''
            },
            mode: 'CREATE_MODE'
        }
    },
    methods: {
        formSubmit: function(){

            console.log("Enter formSubmit()");

            console.log('account', this.requestParam.account);
            console.log('password', this.requestParam.password);
            console.log('passwordAgain', this.requestParam.passwordAgain);
            console.log('mode', this.mode);


            if(this.requestParam.password != this.requestParam.passwordAgain){
                alert("两次输入密码不一致，请重新输入");
                return;
            }

            $.ajax({
                type : "POST",
                url : basicUrl + '/createAdmin',
                data : {
                    'account': this.requestParam.account,
                    'password': this.requestParam.password,
                    'mode': this.mode
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "admin-list";
                        customContent.resultList = resp;
                        breadcrumb.currentLocation = "管理员列表";
                    }else if(!resp.status){
                        alert(resp.description);
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });
        }
    }
});

Vue.component('change-password', {
    props : ['list'],
    template : '#changePasswordTemplate',
    data: function(){
        return {
            account: '',
            password: '',
            passwordAgain: '',
            mode: 'EDIT_MODE'
        }
    },
    created: function(){
        this.account = this.$parent.resultList;
    },
    methods: {
        formSubmit: function(){

            console.log("Enter formSubmit()");

            console.log('account', this.account);
            console.log('password', this.password);
            console.log('password', this.passwordAgain);
            console.log('mode', this.mode);

            if(this.password != this.passwordAgain){
                alert("两次输入的密码不一致，请重新输入");
                return;
            }

            $.ajax({
                type : "POST",
                url : basicUrl + '/changePassword',
                data : {
                    'account': this.account,
                    'password': this.password,
                    'mode': this.mode
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    axios.get(basicUrl + '/robot/group-list')
                        .then(function(resp) {

                            console.log("resp.data:", resp.data);

                            customContent.currentView = "group-list";
                            customContent.resultList = resp.data;
                            breadcrumb.currentLocation = "群列表";

                        })
                        .catch(function(error) {
                            alert("axios异常，请查看系统日志以排查问题");
                        });
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });
        }
    }
});

Vue.component('edit-auto-reply', {
    props : ['list'],
    template : '#editAutoReplyTemplate',
    data: function(){
        return {
            mode: 'EDIT_MODE'
        }
    },

    methods: {
        removePic: function(){
            this.list.imgToSend = '';
            this.list.selectedImgUrl = '';
            //清除file input
            $("#imgToSend").val("");
        },
        exit: function(){
            axios.get(basicUrl + '/robot/auto-reply-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "auto-reply-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "群自动回复关键词列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },
        formSubmit: function(){

            console.log("Enter formSubmit()");

            console.log('keyword', this.list.keyword);
            console.log('ignoredSender', this.list.ignoredSender);
            console.log('textToSend1', this.list.textToSend1);
            console.log('textToSend2', this.list.textToSend2);
            console.log('imgToSend', this.list.imgToSend);
            console.log('wxGroupSelected', this.list.wxGroupSelected);
            console.log('mode', this.mode);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/autoReply',
                data : {
                    'keyword': this.list.keyword,
                    'ignoredSender': this.list.ignoredSender,
                    'textToSend1': this.list.textToSend1,
                    'textToSend2': this.list.textToSend2,
                    'imgToSend': this.list.imgToSend,
                    'wxGroupSelected': this.list.wxGroupSelected.toString(),
                    'mode': this.mode
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "auto-reply-list";
                        customContent.resultList = resp;
                        breadcrumb.currentLocation = "群自动回复关键词列表";
                    }else if(!resp.status){
                        alert(resp.description);
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });
            //看来没有必要把参数发给父组件来调用POST请求，直接在本组件中就可以完成了，所以注释掉下面两行
            //console.log("emit to form-submit-click, which is bound to realFormSubmitHandler()");
            //this.$emit('form-submit-click', actionType, this.requestParam);
        },

        fileChange: function(event){
            console.log("Enter fileChange()");
            console.log("event.target.files[0]: ", event.target.files[0]);
            console.log("event.target.files[0].name: ", event.target.files[0].name);

            formdata = new FormData();
            formdata.append('fileContent', event.target.files[0]);
            formdata.append('expectedFolder','autoReply');
            formdata.append('expectedFileName','');

            axios({
                url: basicUrl + '/robot/upload',
                method: 'post',
                data: formdata,
                headers: {'Content-Type': 'application/multipart/form-data'}
            })
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    if(resp.data.status == 'true'){
                        this.list.imgToSend = resp.data.imgToSend;
                        this.list.selectedImgUrl = resp.data.selectedImgUrl;
                        $("#imgToSend").val("");
                    }else{
                        alert("resp.data.description");
                    }

                }.bind(this))
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        }
    }
});

Vue.component('edit-scheduled-task', {
    props : ['list'],
    template : '#editScheduledTaskTemplate',
    data: function(){
        return {
            mode: 'EDIT_MODE'
        }
    },

    methods: {
        removePic: function(){
            this.list.imgToSend = '';
            this.list.selectedImgUrl = '';
            //清除file input
            $("#imgToSend").val("");
        },
        exit: function(){
            axios.get(basicUrl + '/robot/scheduled-task-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "scheduled-task-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "定时任务列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },
        formSubmit: function(){

            console.log("Enter formSubmit()");

            console.log('keyword', this.list.keyword);
            console.log('scheduledTime', this.list.scheduledTime);
            console.log('textToSend1', this.list.textToSend1);
            console.log('textToSend2', this.list.textToSend2);
            console.log('imgToSend', this.list.imgToSend);
            console.log('wxGroupSelected', this.list.wxGroupSelected);
            console.log('friendReceivers', this.list.friendReceivers);
            console.log('jobClassName', this.list.jobClassName);
            console.log('mode', this.mode);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/scheduledTask',
                data : {
                    'keyword': this.list.keyword,
                    'scheduledTime': this.list.scheduledTime,
                    'textToSend1': this.list.textToSend1,
                    'textToSend2': this.list.textToSend2,
                    'imgToSend': this.list.imgToSend,
                    'wxGroupSelected': this.list.wxGroupSelected.toString(),
                    'friendReceivers': this.list.friendReceivers,
                    'jobClassName': this.list.jobClassName,
                    'mode': this.mode
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "scheduled-task-list";
                        customContent.resultList = resp;
                        breadcrumb.currentLocation = "定时任务列表";
                    }else if(!resp.status){
                        alert(resp.description);
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });
        },

        fileChange: function(event){
            console.log("Enter fileChange()");
            console.log("event.target.files[0]: ", event.target.files[0]);
            console.log("event.target.files[0].name: ", event.target.files[0].name);

            formdata = new FormData();
            formdata.append('fileContent', event.target.files[0]);
            formdata.append('expectedFolder','scheduledTask');
            formdata.append('expectedFileName','');

            axios({
                url: basicUrl + '/robot/upload',
                method: 'post',
                data: formdata,
                headers: {'Content-Type': 'application/multipart/form-data'}
            })
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    if(resp.data.status == 'true'){
                        this.list.imgToSend = resp.data.imgToSend;
                        this.list.selectedImgUrl = resp.data.selectedImgUrl;
                        $("#imgToSend").val("");
                    }else{
                        alert("resp.data.description");
                    }

                }.bind(this))
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },
        testCron: function () {
            console.log("进入testCron()");

            console.log('cron', this.list.scheduledTime);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/testCron',
                data : {
                    'cron': this.list.scheduledTime
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    alert(resp);
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        }
    }
});

Vue.component('edit-welcome-msg', {
    props : ['list'],
    template : '#editWelcomeMsgTemplate',
    data: function(){
        return {
            mode: 'EDIT_MODE'
        }
    },
    methods: {
        removePic: function(){
            this.list.imgToSend = '';
            this.list.selectedImgUrl = '';
            //清除file input
            $("#imgToSend").val("");
        },
        exit: function(){
            axios.get(basicUrl + '/robot/welcome-msg-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "welcome-msg-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "欢迎消息列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },
        formSubmit: function(){

            console.log("Enter formSubmit()");

            console.log('keyword', this.list.keyword);
            console.log('threshold', this.list.threshold);
            console.log('textToSend1', this.list.textToSend1);
            console.log('textToSend2', this.list.textToSend2);
            console.log('imgToSend', this.list.imgToSend);
            console.log('wxGroupSelected', this.list.wxGroupSelected);
            console.log('mode', this.mode);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/welcomeMsg',
                data : {
                    'keyword': this.list.keyword,
                    'threshold': this.list.threshold,
                    'textToSend1': this.list.textToSend1,
                    'textToSend2': this.list.textToSend2,
                    'imgToSend': this.list.imgToSend,
                    'wxGroupSelected': this.list.wxGroupSelected.toString(),
                    'mode': this.mode
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "welcome-msg-list";
                        customContent.resultList = resp;
                        breadcrumb.currentLocation = "欢迎消息列表";
                    }else if(!resp.status){
                        alert(resp.description);
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        },
        fileChange: function(event){
            console.log("Enter fileChange()");
            console.log("event.target.files[0]: ", event.target.files[0]);
            console.log("event.target.files[0].name: ", event.target.files[0].name);

            formdata = new FormData();
            formdata.append('fileContent', event.target.files[0]);
            formdata.append('expectedFolder','welcomeMsg');
            formdata.append('expectedFileName','');

            axios({
                url: basicUrl + '/robot/upload',
                method: 'post',
                data: formdata,
                headers: {'Content-Type': 'application/multipart/form-data'}
            })
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    if(resp.data.status == 'true'){
                        this.list.imgToSend = resp.data.imgToSend;
                        this.list.selectedImgUrl = resp.data.selectedImgUrl;
                        $("#imgToSend").val("");
                    }else{
                        alert("resp.data.description");
                    }

                }.bind(this))
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        }
    }
});

//welcome-msg组件已弃用，以后可以尝试再次使用该组件，把欢迎消息的查看、编辑和新增放在同一个template中
Vue.component('welcome-msg', {
    props : ['list'],
    template : '#welcomeMsgTemplate',
    data: function(){
        return {
            requestParam: {
                keyword: '',
                threshold: '',
                textToSend1: '',
                textToSend2: '',
                imgToSend: '',
                wxGroupSelected: [],
                wxGroupAll: []
            },
            mode: '',
        }
    },
    created: function() {
        console.log("进入welcome-msg created()");
        console.log("this.$parent: ", this.$parent.resultList);
        console.log("this.$parent.mode: ", this.$parent.mode);
        //$parent即父组件customContent
        this.mode = this.$parent.mode;

        if(this.mode == "CREATE_MODE"){
            this.requestParam.keyword = '';
            this.requestParam.threshold = '';
            this.requestParam.textToSend1 = '';
            this.requestParam.textToSend2 = '';
            this.requestParam.imgToSend = '';
            this.requestParam.wxGroupSelected = [];
            this.requestParam.wxGroupAll = [];
        }else{
            this.requestParam = this.$parent.resultList;
        }
    },

    mounted: function(){
        console.log("进入welcome-msg mounted()");

        //mounted()执行的时候，DOM已经render完毕，这时可以判断select的哪些option是被选中的状态：
        this.determinWhichOptionSelected();
    },
    methods: {
        determinWhichOptionSelected: function(){
            var all_options = document.getElementById("wxGroupSelected").options;
            for (i=0; i<all_options.length; i++){

                console.log("all_options[i].label", all_options[i].label);

                for(j=0; j<this.requestParam.wxGroupSelected.length; j++){

                    console.log("this.requestParam.wxGroupSelected[j]", this.requestParam.wxGroupSelected[j]);

                    if (all_options[i].value == this.requestParam.wxGroupSelected[j]){
                        all_options[i].selected = true;
                    }
                }
            }
        },
        removePic: function(e){
            this.imgToSend = '';
            document.getElementById("oldPic").style = "display:none";
            document.getElementById("selectPic").style = "display:block";
            e.preventDefault();
        },
        exitEdit: function(e){

            e.preventDefault();
        },
        convertToEditMode: function(e){
            console.log("进入convertToEditMode()");
            this.mode = "EDIT_MODE";
            this.$parent.currentLocation = "编辑欢迎消息";
            //this.determinWhichOptionSelected();
            e.preventDefault();
        },
        formSubmit: function(){

            console.log("Enter formSubmit()");

            console.log('keyword', this.requestParam.keyword);
            console.log('threshold', this.requestParam.threshold);
            console.log('textToSend1', this.requestParam.textToSend1);
            console.log('textToSend2', this.requestParam.textToSend2);
            console.log('imgToSend', this.requestParam.imgToSend);
            console.log('wxGroupSelected', this.requestParam.wxGroupSelected);
            console.log('mode', this.mode);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/welcomeMsg',
                data : {
                    'keyword': this.requestParam.keyword,
                    'threshold': this.requestParam.threshold,
                    'textToSend1': this.requestParam.textToSend1,
                    'textToSend2': this.requestParam.textToSend2,
                    'imgToSend': this.requestParam.imgToSend,
                    'wxGroupSelected': this.requestParam.wxGroupSelected.toString(),
                    'mode': this.mode
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "welcome-msg-list";
                        customContent.resultList = resp;
                        breadcrumb.currentLocation = "欢迎消息列表";
                    }else if(!resp.status){
                        alert("操作失败，请查看系统日志以排查问题");
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        },

        formReset: function(){
            console.log("Enter formReset()");

            this.requestParam.keyword = '';
            this.requestParam.threshold = '';
            this.requestParam.textToSend1 = '';
            this.requestParam.textToSend2 = '';
            this.requestParam.imgToSend = '';
            this.requestParam.wxGroupSelected = [];
            this.requestParam.selectedImgUrl = '';

            //清除file input
            $("#imgToSend").val("");
        },

        fileChange: function(event){
            console.log("Enter fileChange()");
            console.log("event.target.files[0]: ", event.target.files[0]);
            console.log("event.target.files[0].name: ", event.target.files[0].name);

            formdata = new FormData();
            formdata.append('fileContent', event.target.files[0]);
            formdata.append('expectedFolder','welcomeMsg');
            formdata.append('expectedFileName','');

            axios({
                url: basicUrl + '/robot/upload',
                method: 'post',
                data: formdata,
                headers: {'Content-Type': 'application/multipart/form-data'}
            })
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    if(resp.data.status == 'true'){
                        this.requestParam.imgToSend = resp.data.imgToSend;
                        this.requestParam.selectedImgUrl = resp.data.selectedImgUrl;
                    }else{
                        alert("resp.data.description");
                    }

                }.bind(this))
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        }
    }
});

Vue.component('read-welcome-msg', {
    props : ['list'],
    template : '#readWelcomeMsgTemplate',

    methods: {
        edit: function () {
            console.log("进入edit()");

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/getWelcomeMsg',
                data : {
                    'name': this.list.keyword
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "edit-welcome-msg";
                        customContent.resultList = resp;
                        customContent.mode = "EDIT_MODE"
                        breadcrumb.currentLocation = "编辑欢迎消息";
                    }else if(!resp.status){
                        alert("操作失败，请查看系统日志以排查问题");
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        },
        exit: function(){
            axios.get(basicUrl + '/robot/welcome-msg-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "welcome-msg-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "欢迎消息列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        }
    }
});

Vue.component('read-auto-reply', {
    props : ['list'],
    template : '#readAutoReplyTemplate',
    data: function(){
        return {
            mode: 'READ_MODE',
        }
    },

    methods: {
        edit: function () {
            console.log("进入edit()");

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/getAutoReply',
                data : {
                    'name': this.list.keyword
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "edit-auto-reply";
                        customContent.resultList = resp;
                        customContent.mode = "EDIT_MODE"
                        breadcrumb.currentLocation = "编辑自动回复";
                    }else if(!resp.status){
                        alert("操作失败，请查看系统日志以排查问题");
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        },
        exit: function(){
            axios.get(basicUrl + '/robot/auto-reply-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "auto-reply-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "群自动回复关键词列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        }
    }
});

Vue.component('read-scheduled-task', {
    props : ['list'],
    template : '#readScheduledTaskTemplate',
    data: function(){
        return {
            mode: 'READ_MODE'
        }
    },
    methods: {
        edit: function () {
            console.log("进入edit()");

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/getScheduledTask',
                data : {
                    'name': this.list.keyword
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "edit-scheduled-task";
                        customContent.resultList = resp;
                        customContent.mode = "EDIT_MODE"
                        breadcrumb.currentLocation = "编辑定时任务";
                    }else if(!resp.status){
                        alert("操作失败，请查看系统日志以排查问题");
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        },
        exit: function(){
            axios.get(basicUrl + '/robot/scheduled-task-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "scheduled-task-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "定时任务列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },
        testCron: function () {
            console.log("进入testCron()");

            console.log('cron', this.list.scheduledTime);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/testCron',
                data : {
                    'cron': this.list.scheduledTime
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    alert(resp);
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        }
    }
});

Vue.component('read-log', {
    props: ['list'],
    template: '#readLogTemplate',
    mounted: function(){
        console.log("进入 mounted()");
        var logarea = document.getElementById('logarea')
        logarea.focus();
        this.moveToEnd(logarea);
    },
    methods: {

        exit: function(event, actionType){
            console.log("进入exit()");
            this.$emit('log-button-click', event.target, actionType);
        },

        refresh: function(event, actionType){
            console.log("进入refresh()");
            this.$emit('log-button-click', event.target, actionType);
        },

        moveToEnd: function (el) {
            if (typeof el.selectionStart == "number") {
                el.selectionStart = el.selectionEnd = el.value.length;
            } else if (typeof el.createTextRange != "undefined") {
                el.focus();
                var range = el.createTextRange();
                range.collapse(false);
                range.select();
            }
        }
    }
});

Vue.component('robot-login', {
    props: ['list', 'qrurl', 'msg'],
    template: '#robotLoginTemplate',
    methods: {
        robotLogin: function () {

            axios.get(basicUrl + '/robot/onboard')
                .then(function (resp) {

                    console.log("robot login resp.data:", resp.data);

                    if (typeof(resp.data.qrCodeFileAccessUrl) != "undefined") {

                        console.log("emit to robot-login-click, which is bound to realRobotLoginActionHandler()");
                        this.$emit('robot-login-click', resp.data);

                    } else {

                        if (resp.data.status == "ROBOT_IS_INITIALIZING") {
                            alert("机器人上一次初始化尚未完成，请稍后再试");
                        }
                    }
                }.bind(this))
                .catch(function (error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },
        getQrCodeSuccess: function(resp) {

            console.log("resp.data.qrCodeFileAccessUrl: ", resp.data.qrCodeFileAccessUrl);

            app.btnClass = {
                'hide': true
            };
            app.imgClass = {
                'hide': false
            };
            app.spanClass = {
                'hide': false,
                'label-primary': true
            };
            app.imgUrl = resp.data.qrCodeFileAccessUrl;
            app.message = '使用手机微信扫码登录';
        }
    }
});

Vue.component('friend-auto-reply', {
    props: ['list'],
    template: '#friendAutoReplyTemplate',
    methods: {
        buttonClick: function (event, actionType){
            console.log("进入button-click()");
            this.$emit('auto-reply-button-click', event.target, actionType);
        }
    }
});

Vue.component('create-scheduled-task', {
    props : ['list'],
    template : '#createScheduledTaskTemplate',
    data: function(){
        return {
            requestParam: {
                keyword: '',
                scheduledTime: '',
                textToSend1: '',
                textToSend2: '',
                imgToSend: '',
                wxGroupSelected: [],
                friendReceivers: '',
                jobClassName: 'CommonJob',
                selectedImgUrl: ''
            },
            mode: 'CREATE_MODE'
        }
    },
    methods: {
        removePic: function(){
            this.requestParam.imgToSend = '';
            this.requestParam.selectedImgUrl = '';
            //清除file input
            $("#imgToSend").val("");

        },
        formSubmit: function(){

            console.log("Enter formSubmit()");

            console.log('keyword', this.requestParam.keyword);
            console.log('scheduledTime', this.requestParam.scheduledTime);
            console.log('textToSend1', this.requestParam.textToSend1);
            console.log('textToSend2', this.requestParam.textToSend2);
            console.log('imgToSend', this.requestParam.imgToSend);
            console.log('wxGroupSelected', this.requestParam.wxGroupSelected);
            console.log('friendReceivers', this.requestParam.friendReceivers);
            console.log('jobClassName', this.requestParam.jobClassName);
            console.log('mode', this.mode);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/scheduledTask',
                data : {
                    'keyword': this.requestParam.keyword,
                    'scheduledTime': this.requestParam.scheduledTime,
                    'textToSend1': this.requestParam.textToSend1,
                    'textToSend2': this.requestParam.textToSend2,
                    'imgToSend': this.requestParam.imgToSend,
                    'wxGroupSelected': this.requestParam.wxGroupSelected.toString(),
                    'friendReceivers': this.requestParam.friendReceivers,
                    'jobClassName': this.requestParam.jobClassName,
                    'mode': this.mode
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "scheduled-task-list";
                        customContent.resultList = resp;
                        breadcrumb.currentLocation = "定时任务列表";
                    }else if(!resp.status){
                        alert(resp.description);
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        },

        formReset: function(){
            console.log("Enter formReset()");

            this.requestParam.keyword = '';
            this.requestParam.scheduledTime = '';
            this.requestParam.textToSend1 = '';
            this.requestParam.textToSend2 = '';
            this.requestParam.imgToSend = '';
            this.requestParam.wxGroupSelected = [];
            this.requestParam.friendReceivers = '';
            this.requestParam.selectedImgUrl = '';

            //清除file input
            $("#imgToSend").val("");
        },

        fileChange: function(event){
            console.log("Enter fileChange()");
            console.log("event.target.files[0]: ", event.target.files[0]);
            console.log("event.target.files[0].name: ", event.target.files[0].name);

            formdata = new FormData();
            formdata.append('fileContent', event.target.files[0]);
            formdata.append('expectedFolder','scheduledTask');
            formdata.append('expectedFileName','');

            axios({
                url: basicUrl + '/robot/upload',
                method: 'post',
                data: formdata,
                headers: {'Content-Type': 'application/multipart/form-data'}
            })
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    if(resp.data.status == 'true'){
                        this.requestParam.imgToSend = resp.data.imgToSend;
                        this.requestParam.selectedImgUrl = resp.data.selectedImgUrl;
                    }else{
                        alert("resp.data.description");
                    }

                }.bind(this))
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },
        testCron: function () {
            console.log("进入testCron()");

            console.log('cron', this.requestParam.scheduledTime);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/testCron',
                data : {
                    'cron': this.requestParam.scheduledTime
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    alert(resp);
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        }
    }
});

Vue.component('welcome-msg-list', {
    props : ['list'],
    template : '#welcomeMsgListTemplate',
    methods: {
    	buttonClick: function(event, actionType){
    		
    	      console.log("Enter buttonClick()");
    	      console.log("event.target: ", event.target);
              console.log("actionType: ", actionType);

              if(actionType == 'REMOVE_WELCOME_MSG'){
                  var r = confirm("确定要删除吗？");
                  if (!r)
                  {
                      return;
                  }
              };

    	      console.log("emit to welcome-msg-button-click, which is bound to realWelcomeMsgActionHandler()");
    	      this.$emit('welcome-msg-button-click', event.target, actionType);
    	}    	
    }
});

Vue.component('scheduled-task-list', {
    props : ['list'],
    template : '#scheduledTaskListTemplate',
    methods: {
    	buttonClick: function(event, actionType){
    		
    	      console.log("Enter buttonClick()");
    	      console.log("event.target: ", event.target);
              console.log("actionType: ", actionType);

              if(actionType == 'REMOVE_SCHEDULED_TASK'){
                  var r = confirm("确定要删除吗？");
                  if (!r)
                  {
                      return;
                  }
              };

    	      console.log("emit to scheduled-task-button-click, which is bound to realScheduledTaskActionHandler()");
    	      this.$emit('scheduled-task-button-click', event.target, actionType);
    	}    	
    }
});

Vue.component('admin-list', {
    props : ['list'],
    template : '#adminListTemplate',
    methods: {
        buttonClick: function(event, actionType){

            console.log("Enter buttonClick()");
            console.log("event.target: ", event.target);
            console.log("actionType: ", actionType);

            if(actionType == 'REMOVE_ADMIN'){
                var r = confirm("确定要删除吗？");
                if (!r)
                {
                    return;
                }
            };
            console.log("emit to admin-button-click, which is bound to realAdminActionHandler()");
            this.$emit('admin-button-click', event.target, actionType);
        }
    }
});

var sidebar = new Vue({
    el: '#sidebar',

    data: {
        robotInfo: {
            online: false,
            initializing: false,
            healthy: false,
            avatar: '',
            nickName: ''
        }
    },

    methods: {
        groupListClick: function() {
            console.log("Enter groupListClick()");

            axios.get(basicUrl + '/robot/group-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "group-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "群列表";

                }.bind(this))
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });

        },

        friendListClick: function() {
            console.log("Enter friendListClick()");

            axios.get(basicUrl + '/robot/friend-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "friend-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "好友列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },

        sendMsgClick: function() {
            console.log("Enter sendMsgClick()");

            axios.get(basicUrl + '/robot/group-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "send-msg";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "发送消息";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });

        },

        autoReplyListClick: function() {
            console.log("Enter autoReplyListClick()");

            axios.get(basicUrl + '/robot/auto-reply-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "auto-reply-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "群自动回复关键词列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });

        },

        createAutoReply: function() {
            console.log("Enter createAutoReply()");

            axios.get(basicUrl + '/robot/group-list?type=registered')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "create-auto-reply";
                    customContent.resultList = resp.data;
                    customContent.mode = "CREATE_MODE";
                    breadcrumb.currentLocation = "新增自动回复关键词";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },

        welcomeMsgListClick: function() {
            console.log("Enter welcomeMsgListClick()");

            axios.get(basicUrl + '/robot/welcome-msg-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "welcome-msg-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "欢迎消息列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });

        },

        createWelcomeMsg: function() {
            console.log("Enter createWelcomeMsg()");

            axios.get(basicUrl + '/robot/group-list?type=registered')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "create-welcome-msg";
                    customContent.resultList = resp.data;
                    customContent.mode = "CREATE_MODE";
                    breadcrumb.currentLocation = "新增欢迎消息";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },

        scheduledTaskListClick: function() {
            console.log("Enter scheduledTaskListClick()");

            axios.get(basicUrl + '/robot/scheduled-task-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "scheduled-task-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "定时任务列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });

        },

        createScheduledTask: function() {
            console.log("Enter createScheduledTask()");

            axios.get(basicUrl + '/robot/group-list?type=registered')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "create-scheduled-task";
                    customContent.resultList = resp.data;
                    customContent.mode = "CREATE_MODE";
                    breadcrumb.currentLocation = "新增定时任务";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },

        adminListClick: function() {
            console.log("Enter adminListClick()");

            axios.get(basicUrl + '/admin-list')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    customContent.currentView = "admin-list";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "管理员列表";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },

        createAdmin: function() {
            console.log("Enter createAdmin()");

            customContent.currentView = "create-admin";
            customContent.mode = "CREATE_MODE";
            breadcrumb.currentLocation = "新增管理员";
        },

        readLog: function() {
            console.log("Enter readLog()");

            axios.get(basicUrl + '/read-log')
                .then(function(resp) {

                    customContent.currentView = "read-log";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "系统日志";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },

        friendAutoReplyClick: function() {
            console.log("Enter friendAutoReplyClick()");

            axios.get(basicUrl + '/robot/friendAutoReply/get')
                .then(function(resp) {

                    customContent.currentView = "friend-auto-reply";
                    customContent.resultList = resp.data;
                    breadcrumb.currentLocation = "好友自动回复状态";

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },
        robotLoginClick: function(){
            console.log("Enter robotLoginClick()");

            customContent.currentView = "robot-login";
            customContent.qrCodeFileUrl = '';
            customContent.remoteMsg = '';
            sidebar.robotInfo.online = false;
            userPanel.robotInfo.online = false;
            userPanel.robotInfo.healthy = false;
            userPanel.robotInfo.avatar = '';
            userPanel.robotInfo.nickName = ''

            breadcrumb.currentLocation = "机器人登录";
        },

        robotLogoutClick: function(){
            console.log("Enter robotLogoutClick()");

            var r = confirm("确定要下线吗？");
            if (!r)
            {
                return;
            }

            axios.get(basicUrl + '/robot/quit')
                .then(function (resp) {

                    console.log("robot login resp.data:", resp.data);
                    customContent.getRobotStatus();

                })
                .catch(function (error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        }
    }
})

var breadcrumb = new Vue({
    el: '#breadcrumb',
    data: {
        currentLocation: '群列表'
    },
    methods: {
        homeClick: function(){
            this.currentLocation = "群列表";
        }
    }
});

var customMenu = new Vue({
    el: '#customMenu',
    data: {

    },
    methods: {
        changePassword : function(event){
            console.log("Enter changePassword()");
            console.log("user: ", event.target.rel);

            customContent.currentView = "change-password";
            customContent.resultList = event.target.rel;
            breadcrumb.currentLocation = "修改密码";
        }
    }
});

var userPanel = new Vue({
    el: '#userPanel',
    data: {
        robotInfo: {
            online: false,
            initializing: false,
            healthy: false,
            avatar: '',
            nickName: ''
        }
    }
});

var customContent = new Vue({
    el: '#customContent',

    data: {
        currentView: "",
        resultList: '',
        groupName: '',
        mode: '',
        qrCodeFileUrl: '',
        remoteMsg: ''
    },

    created: function(){
    	this.getRobotStatus();
    },
    
    methods: {
        getRobotStatus: function(){
            axios.get(basicUrl + '/robot/info')
                .then(function(resp) {

                    console.log("resp.data:", resp.data);

                    sidebar.robotInfo = resp.data;
                    userPanel.robotInfo = resp.data;

                    if(resp.data.online){

                        sidebar.robotInfo = resp.data;
                        userPanel.robotInfo = resp.data;

                        axios.get(basicUrl + '/robot/group-list')
                            .then(function(resp) {

                                console.log("resp.data:", resp.data);

                                customContent.currentView = "group-list";
                                customContent.resultList = resp.data;
                                breadcrumb.currentLocation = "群列表";

                            }.bind(this))
                            .catch(function(error) {
                                alert("axios异常，请查看系统日志以排查问题");
                            });

                    }else{
                        customContent.qrCodeFileUrl = '';
                        customContent.remoteMsg = '';
                        customContent.currentView = "robot-login";
                        breadcrumb.currentLocation = "机器人登录";
                    }
                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },

        //群列表和好友列表里相关按键的处理放在这里
        realActionHandler: function(target, actionType){

            var currentNode = target.nodeName;
            var parentNode = target.parentNode;
            var name = null;
            var value = null;

            if(currentNode == 'I'){
                name = parentNode.name;
                value = parentNode.value;
            }else{
                name = target.name;
                value = target.value;
            }

            console.log("Enter realActionHandler()");
            console.log("target: ", target);
            console.log("currentNode: ", currentNode);
            console.log("parentNode: ", parentNode);
            console.log("name: ", name);
            console.log("value: ", value);
            console.log("actionType: ", actionType);
                        	
            switch (actionType) {
            
	            case "CHECK_MEMBER":
	            	//name是group名称， value是member userName
	            	this.checkMember(name, value);
	            	break;
	            	
	            case "REMOVE_FROM_CTRL":
	            	this.removeCtrl(value);
	            	break;
	            	
	            case "ADD_TO_CTRL":
	            	this.addCtrl(value);
	            	break;
	            	
	            case "DISABLE_SIGN_IN":
	            	this.disableSignIn(value);
	            	break;
	            	
	            case "ENABEL_SIGN_IN":
	            	this.enableSignIn(value);
	            	break;
	            	
	            case "UPDATE_GROUP":
	            	this.updateGroup(value);
	            	break;

                case "SEND_WELCOME_MSG":
                    this.sendWelcomeMsg(value);
                    break;

                case "SIGN_IN":
                	//name是group名称， value是member的昵称
                    this.memberSignIn(name, value);
                    break;
                    
                case "REMOVE_FROM_ADMIN":
                    this.removeFromAdmin(value);
                    break;

                case "ADD_TO_ADMIN":
                	this.addToAdmin(value);
                    break;

                case "DISABLE_RECEIVE_MSG":
                	this.disReceiveMsg(value);
                    break;

                case "ENABEL_RECEIVE_MSG":
                	this.enReceiveMsg(value);
                    break;

	            default:
	            	break;            
            }                      
        },  
        
        addCtrl: function(groupId){
            
            console.log("groupId:", groupId);
            
            axios.get(basicUrl + '/robot/addCtrl/' + groupId)
                 .then(function(resp) {

                     console.log(resp.data);              

                     console.log("typeof(resp.data.status): ", typeof(resp.data.status));
                     
                    if(typeof(resp.data.status) == "undefined"){
                        customContent.currentView = "group-list";
                        customContent.resultList = resp.data;
                        breadcrumb.currentLocation = "群列表";
                    }else if(!resp.data.status){
                    	alert("操作失败，请查看系统日志以排查问题");
                    }

                 })
                 .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                 });
        }, 
        
        removeCtrl: function(groupId){
                       
            console.log("groupId:", groupId);
            
            axios.get(basicUrl + '/robot/removeCtrl/' + groupId)
                 .then(function(resp) {

                     console.log(resp.data);              

                     console.log("typeof(resp.data.status): ", typeof(resp.data.status));
                     
                    if(typeof(resp.data.status) == "undefined"){
                        customContent.currentView = "group-list";
                        customContent.resultList = resp.data;
                        breadcrumb.currentLocation = "群列表";
                    }else if(!resp.data.status){
                    	alert("操作失败，请查看系统日志以排查问题");
                    }

                 })
                 .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                 });            
        },
        
        enableSignIn: function(groupId){
            
            
            console.log("groupId:", groupId);
            
            axios.get(basicUrl + '/robot/enSignIn/' + groupId)
                 .then(function(resp) {

                     console.log(resp.data);              

                     console.log("typeof(resp.data.status): ", typeof(resp.data.status));
                     
                    if(typeof(resp.data.status) == "undefined"){
                        customContent.currentView = "group-list";
                        customContent.resultList = resp.data;
                        breadcrumb.currentLocation = "群列表";
                    }else if(!resp.data.status){
                    	alert("操作失败，请查看系统日志以排查问题");
                    }

                 })
                 .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                 });
        },    
        
        disableSignIn: function(groupId){
            
            
            console.log("groupId:", groupId);
            
            axios.get(basicUrl + '/robot/disSignIn/' + groupId)
                 .then(function(resp) {

                     console.log(resp.data);              

                     console.log("typeof(resp.data.status): ", typeof(resp.data.status));
                     
                    if(typeof(resp.data.status) == "undefined"){
                        customContent.currentView = "group-list";
                        customContent.resultList = resp.data;
                        breadcrumb.currentLocation = "群列表";
                    }else if(!resp.data.status){
                    	alert("操作失败，请查看系统日志以排查问题");
                    }

                 })
                 .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                 });
        },
        
        updateGroup: function(groupId){
            
            
            console.log("groupId:", groupId);
            
            axios.get(basicUrl + '/robot/updateGroup/' + groupId)
                 .then(function(resp) {

                     console.log(resp.data);              

                     console.log("typeof(resp.data.status): ", typeof(resp.data.status));
                     
                    if(typeof(resp.data.status) == "undefined"){
                        customContent.currentView = "group-list";
                        customContent.resultList = resp.data;
                        breadcrumb.currentLocation = "群列表";
                    }else if(!resp.data.status){
                    	alert("操作失败，请查看系统日志以排查问题");
                    }

                 })
                 .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                 });
        },

        sendWelcomeMsg: function(groupId){

            console.log("groupId:", groupId);

            var r = confirm("确定要发送欢迎消息吗？");
            if (!r)
            {
                return;
            }

            axios.get(basicUrl + '/robot/sendWelcomeMsg/' + groupId)
                .then(function(resp) {

                    console.log(resp.data);

                    alert(resp.data.description);

                })
                .catch(function(error) {
                    alert("axios异常，请查看系统日志以排查问题");
                });
        },

        checkMember: function(name, groupId){
            
        	console.log("name:", name);
            console.log("groupId:", groupId);
            
            axios.get(basicUrl + '/robot/getMember/' + groupId)
                 .then(function(resp) {

                     console.log("resp.data:", resp.data);              

                     customContent.currentView = "member-list";
                     customContent.resultList = resp.data;
                     customContent.groupName = name;
                     breadcrumb.currentLocation = "成员列表";
                     
                   })
                   .catch(function(error) {
                        alert("axios异常，请查看系统日志以排查问题");
                   });
        },
        
        memberSignIn: function(groupName, memberName) {
        	
            console.log("groupName:", groupName);
            console.log("memberName:", memberName);

            $.ajax({
                type : "POST",
                url : basicUrl + '/robot/signIn',
                data : {
                    'group': groupName,
                    'member': memberName
                },
                dataType : "json",
                async : true,
                success : function(resp) {
                    console.log("resp:", resp);

                    if(typeof(resp.status) == "undefined"){
                        customContent.currentView = "member-list";
                        customContent.resultList = resp;
                        breadcrumb.currentLocation = "成员列表";
                    }else if(!resp.status){
                        alert("操作失败，请查看系统日志以排查问题");
                    }
                },
                error : function(error) {
                    alert("ajax异常，请查看系统日志以排查问题");
                }
            });

        },
        
        removeFromAdmin: function(friendId){

            console.log("friendId:", friendId);

            axios.get(basicUrl + '/robot/removeAdmin/' + friendId)
            .then(function(resp) {

                console.log(resp.data);              

                console.log("typeof(resp.data.status): ", typeof(resp.data.status));
                
               if(typeof(resp.data.status) == "undefined"){
                   customContent.currentView = "friend-list";
                   customContent.resultList = resp.data;
                   breadcrumb.currentLocation = "好友列表";
               }else if(!resp.data.status){
               	   alert("操作失败，请查看系统日志以排查问题");
               }

            })
            .catch(function(error) {
               alert("axios异常，请查看系统日志以排查问题");
            });
        },
        
        addToAdmin: function(friendId){

            console.log("friendId:", friendId);

            axios.get(basicUrl + '/robot/addAdmin/' + friendId)
            .then(function(resp) {

                console.log(resp.data);              

                console.log("typeof(resp.data.status): ", typeof(resp.data.status));
                
               if(typeof(resp.data.status) == "undefined"){
                   customContent.currentView = "friend-list";
                   customContent.resultList = resp.data;
                   breadcrumb.currentLocation = "好友列表";
               }else if(!resp.data.status){
               	   alert("操作失败，请查看系统日志以排查问题");
               }

            })
            .catch(function(error) {
               alert("axios异常，请查看系统日志以排查问题");
            });
        },

        disReceiveMsg: function(friendId){

            console.log("friendId:", friendId);

            axios.get(basicUrl + '/robot/disReceiveMsg/' + friendId)
            .then(function(resp) {

                console.log(resp.data);              

                console.log("typeof(resp.data.status): ", typeof(resp.data.status));
                
               if(typeof(resp.data.status) == "undefined"){
                   customContent.currentView = "friend-list";
                   customContent.resultList = resp.data;
                   breadcrumb.currentLocation = "好友列表";
               }else if(!resp.data.status){
               	   alert("操作失败，请查看系统日志以排查问题");
               }

            })
            .catch(function(error) {
               alert("axios异常，请查看系统日志以排查问题");
            });
        },
        enReceiveMsg: function(friendId){

            console.log("friendId:", friendId);

            axios.get(basicUrl + '/robot/enReceiveMsg/' + friendId)
            .then(function(resp) {

                console.log(resp.data);              

                console.log("typeof(resp.data.status): ", typeof(resp.data.status));
                
               if(typeof(resp.data.status) == "undefined"){
                   customContent.currentView = "friend-list";
                   customContent.resultList = resp.data;
                   breadcrumb.currentLocation = "好友列表";
               }else if(!resp.data.status){
               	   alert("操作失败，请查看系统日志以排查问题");
               }

            })
            .catch(function(error) {
               alert("axios异常，请查看系统日志以排查问题");
            });
        },

        //关键词自动回复列表里相关按键的处理放在这里
        realAutoReplyActionHandler: function(target, actionType){

            var currentNode = target.nodeName;
            var parentNode = target.parentNode;
            var value = null;

            if(currentNode == 'I'){
                var value = parentNode.value;
            }else{
                value = target.value;
            }

            console.log("Enter realAutoReplyActionHandler()");
            console.log("target: ", target);
            console.log("currentNode: ", currentNode);
            console.log("parentNode: ", parentNode);
            console.log("value: ", value);
            console.log("actionType: ", actionType);

            switch (actionType) {

                case "READ_AUTO_REPLY":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/getAutoReply',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "read-auto-reply";
                                customContent.resultList = resp;
                                customContent.mode = "READ_MODE"
                                breadcrumb.currentLocation = "查看自动回复";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "EDIT_AUTO_REPLY":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/getAutoReply',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "edit-auto-reply";
                                customContent.resultList = resp;
                                customContent.mode = "EDIT_MODE"
                                breadcrumb.currentLocation = "编辑自动回复";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "DISABLE_AUTO_REPLY":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/pauseAutoReply',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "auto-reply-list";
                                customContent.resultList = resp;
                                breadcrumb.currentLocation = "群自动回复关键词列表";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

	            case "ENABLE_AUTO_REPLY":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/resumeAutoReply',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "auto-reply-list";
                                customContent.resultList = resp;
                                breadcrumb.currentLocation = "群自动回复关键词列表";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

	            case "REMOVE_AUTO_REPLY":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/removeAutoReply',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "auto-reply-list";
                                customContent.resultList = resp;
                                breadcrumb.currentLocation = "群自动回复关键词列表";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "DISABLE_FRIEND_AUTO_REPLY":
                    axios.get(basicUrl + '/robot/friendAutoReply/disable')
                        .then(function(resp) {

                            customContent.currentView = "friend-auto-reply";
                            customContent.resultList = resp.data;
                            breadcrumb.currentLocation = "好友自动回复状态";

                        })
                        .catch(function(error) {
                            alert("axios异常，请查看系统日志以排查问题");
                        });
                    break;

                case "ENABLE_FRIEND_AUTO_REPLY":
                    axios.get(basicUrl + '/robot/friendAutoReply/enable')
                        .then(function(resp) {

                            customContent.currentView = "friend-auto-reply";
                            customContent.resultList = resp.data;
                            breadcrumb.currentLocation = "好友自动回复状态";

                        })
                        .catch(function(error) {
                            alert("axios异常，请查看系统日志以排查问题");
                        });
                    break;

                default:
	            	break;
            }
        },

        //欢迎消息列表里相关按键的处理放在这里
        realWelcomeMsgActionHandler: function(target, actionType){

            var currentNode = target.nodeName;
            var parentNode = target.parentNode;
            var value = null;

            if(currentNode == 'I'){
                var value = parentNode.value;
            }else{
                value = target.value;
            }

            console.log("Enter realWelcomeMsgActionHandler()");
            console.log("target: ", target);
            console.log("currentNode: ", currentNode);
            console.log("parentNode: ", parentNode);
            console.log("value: ", value);
            console.log("actionType: ", actionType);

            switch (actionType) {

                case "READ_WELCOME_MSG":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/getWelcomeMsg',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "read-welcome-msg";
                                customContent.resultList = resp;
                                customContent.mode = "READ_MODE"
                                breadcrumb.currentLocation = "查看欢迎消息";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "EDIT_WELCOME_MSG":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/getWelcomeMsg',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "edit-welcome-msg";
                                customContent.resultList = resp;
                                customContent.mode = "EDIT_MODE"
                                breadcrumb.currentLocation = "编辑欢迎消息";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "DISABLE_WELCOME_MSG":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/disWelcomeMsg',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "welcome-msg-list";
                                customContent.resultList = resp;
                                breadcrumb.currentLocation = "欢迎消息列表";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "ENABLE_WELCOME_MSG":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/enWelcomeMsg',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "welcome-msg-list";
                                customContent.resultList = resp;
                                breadcrumb.currentLocation = "欢迎消息列表";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "REMOVE_WELCOME_MSG":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/removeWelcomeMsg',
                        data : {
                            'name': value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "welcome-msg-list";
                                customContent.resultList = resp;
                                breadcrumb.currentLocation = "欢迎消息列表";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                default:
                    break;
            }
        },

        //定时任务列表里相关按键的处理放在这里
        realScheduledTaskActionHandler: function(target, actionType){

            var currentNode = target.nodeName;
            var parentNode = target.parentNode;
            var value = null;

            if(currentNode == 'I'){
                var value = parentNode.value;
            }else{
                value = target.value;
            }

            console.log("Enter realScheduledTaskActionHandler()");
            console.log("target: ", target);
            console.log("currentNode: ", currentNode);
            console.log("parentNode: ", parentNode);
            console.log("value: ", value);
            console.log("actionType: ", actionType);

            switch (actionType) {

                case "READ_SCHEDULED_TASK":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/getScheduledTask',
                        data : {
                            "name" : value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "read-scheduled-task";
                                customContent.resultList = resp;
                                customContent.mode = "READ_MODE"
                                breadcrumb.currentLocation = "查看定时任务";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "EDIT_SCHEDULED_TASK":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/getScheduledTask',
                        data : {
                            "name" : value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "edit-scheduled-task";
                                customContent.resultList = resp;
                                customContent.mode = "EDIT_MODE"
                                breadcrumb.currentLocation = "编辑定时任务";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "DISABLE_SCHEDULED_TASK":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/disScheduledTask',
                        data : {
                            "name" : value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "scheduled-task-list";
                                customContent.resultList = resp;
                                breadcrumb.currentLocation = "定时任务列表";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "ENABLE_SCHEDULED_TASK":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/enScheduledTask',
                        data : {
                            "name" : value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "scheduled-task-list";
                                customContent.resultList = resp;
                                breadcrumb.currentLocation = "定时任务列表";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                case "REMOVE_SCHEDULED_TASK":

                    $.ajax({
                        type : "POST",
                        url : basicUrl + '/robot/removeScheduledTask',
                        data : {
                            "name" : value
                        },
                        dataType : "json",
                        async : true,
                        success : function(resp) {
                            console.log("resp:", resp);

                            if(typeof(resp.status) == "undefined"){
                                customContent.currentView = "scheduled-task-list";
                                customContent.resultList = resp;
                                breadcrumb.currentLocation = "定时任务列表";
                            }else if(!resp.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }
                        },
                        error : function(error) {
                            alert("ajax异常，请查看系统日志以排查问题");
                        }
                    });

                    break;

                default:
                    break;
            }
        },

        //管理员列表里相关按键的处理放在这里
        realAdminActionHandler: function(target, actionType){

            console.log("Enter realAdminActionHandler()");

            var currentNode = target.nodeName;
            var parentNode = target.parentNode;
            var value = null;

            if(currentNode == 'I'){
                value = parentNode.value;
            }else{
                value = target.value;
            }

            console.log("target: ", target);
            console.log("currentNode: ", currentNode);
            console.log("parentNode: ", parentNode);
            console.log("value: ", value);
            console.log("actionType: ", actionType);

            switch (actionType) {

                case "READ_ADMIN":

                    break;

                case "EDIT_ADMIN":

                    break;

                case "DISABLE_ADMIN":
                    axios.get(basicUrl + '/disAdmin/' + value)
                        .then(function(resp) {

                            console.log(resp.data);

                            console.log("typeof(resp.data.status): ", typeof(resp.data.status));

                            if(typeof(resp.data.status) == "undefined"){
                                customContent.currentView = "admin-list";
                                customContent.resultList = resp.data;
                                breadcrumb.currentLocation = "管理员列表";
                            }else if(!resp.data.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }

                        })
                        .catch(function(error) {
                            alert("axios异常，请查看系统日志以排查问题");
                        });
                    break;

                case "ENABLE_ADMIN":
                    axios.get(basicUrl + '/enAdmin/' + value)
                        .then(function(resp) {

                            console.log(resp.data);

                            console.log("typeof(resp.data.status): ", typeof(resp.data.status));

                            if(typeof(resp.data.status) == "undefined"){
                                customContent.currentView = "admin-list";
                                customContent.resultList = resp.data;
                                breadcrumb.currentLocation = "管理员列表";
                            }else if(!resp.data.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }

                        })
                        .catch(function(error) {
                            alert("axios异常，请查看系统日志以排查问题");
                        });
                    break;

                case "REMOVE_ADMIN":
                    axios.get(basicUrl + '/removeAdmin/' + value)
                        .then(function(resp) {

                            console.log(resp.data);

                            console.log("typeof(resp.data.status): ", typeof(resp.data.status));

                            if(typeof(resp.data.status) == "undefined"){
                                customContent.currentView = "admin-list";
                                customContent.resultList = resp.data;
                                breadcrumb.currentLocation = "管理员列表";
                            }else if(!resp.data.status){
                                alert("操作失败，请查看系统日志以排查问题");
                            }

                        })
                        .catch(function(error) {
                            alert("axios异常，请查看系统日志以排查问题");
                        });
                    break;

                default:
                    break;
            }
        },

        //系统日志里相关按键的处理放在这里
        realLogActionHandler: function(target, actionType){

            console.log("Enter realLogActionHandler()");
            console.log("target: ", target);
            console.log("actionType: ", actionType);

            switch (actionType) {

                case "REFRESH_LOG":
                    console.log("Enter REFRESH_LOG()");

                    axios.get(basicUrl + '/read-log')
                        .then(function(resp) {

                            customContent.currentView = "read-log";
                            customContent.resultList = resp.data;
                            breadcrumb.currentLocation = "系统日志";

                        })
                        .catch(function(error) {
                            alert("axios异常，请查看系统日志以排查问题");
                        });
                    break;

                case "EXIT_LOG":
                    console.log("Enter EXIT_LOG()");

                    axios.get(basicUrl + '/robot/group-list')
                        .then(function(resp) {

                            console.log("resp.data:", resp.data);

                            customContent.currentView = "group-list";
                            customContent.resultList = resp.data;
                            breadcrumb.currentLocation = "群列表";

                        }.bind(this))
                        .catch(function(error) {
                            alert("axios异常，请查看系统日志以排查问题");
                        });

                    break;

                case "DOWNLOAD_LOG":

                    break;
                default:
                    break;
            }
        },

        //机器人登录的处理放在这里
        realRobotLoginActionHandler: function(data){

            console.log("Enter realRobotLoginActionHandler()");
            console.log("data: ", data);

            this.qrCodeFileUrl = data.qrCodeFileAccessUrl;
            this.remoteMsg = '使用手机微信扫码登录';
        }
    }
});


websocket.onmessage = onServerMsg;

function onServerMsg(msg) {
    console.log("receive msg [" + msg.data + "] from server");

    var obj = eval('(' + msg.data + ')');

    console.log("robot.code: " + obj.code);
    console.log("robot.msg: " + obj.msg);
    console.log("robot.avatar: " + obj.avatar);

    customContent.remoteMsg = obj.msg;

    switch (obj.code) {
        case "200":
            break;

        case "201":
            customContent.qrCodeFileUrl = obj.avatar;
            break;

        case "202":
            customContent.qrCodeFileUrl = basicUrl + '/static/img/astroboy.jpg';
            customContent.getRobotStatus();
            break;

        case "203":
            sidebar.robotInfo.healthy = true;
            userPanel.robotInfo.healthy = true;
            break;

        case "401":
            sidebar.robotInfo.healthy = false;
            userPanel.robotInfo.healthy = false;
            break;

        case "408":
        case "901":
        case "902":
        case "903":
        case "904":
        case "905":

            sidebar.robotInfo.online = false;
            sidebar.robotInfo.healthy = false;

            userPanel.robotInfo.online = false;
            userPanel.robotInfo.healthy = false;

            customContent.qrCodeFileUrl = '';

            break;

        default:
            break;
    }
}